import request from "~/utils/request"
import {
    Classify,
    CommonSearchVO,
    DepartmentClassifyVO,
    DepartmentVO,
    ExcelDomain,
    ImportPageVO,
    ImportResultVO,
    Permission,
    PositionVO,
    Result,
    TableDetailedVO,
    TableFieldVO,
    TableInfoPageVO,
    UserVO
} from "~/api/responseResult";
import {DataImportBO, TablePageQuery, UserQuery} from "~/api/requestInstance";

export function classifyList(): Result<Array<Classify>> {
    return request({
        url: '/classify/classifyList',
        method: 'get'
    }) as any as Result<Array<Classify>>
}


export function tablePage(data: TablePageQuery): Result<Array<TableInfoPageVO>> {
    return request({
        url: '/table/tablePage',
        method: 'post',
        data: data
    }) as any as Result<Array<TableInfoPageVO>>
}

export function userAll(): Result<Array<UserVO>> {
    return request({
        url: '/user/all',
        method: 'get',
    }) as any as Result<Array<UserVO>>
}

export function findUserAllByUserQuery(userQuery: UserQuery): Result<Array<UserVO>> {
    return request({
        url: '/user/findUserAllByUserQuery',
        method: 'post',
        data: userQuery
    }) as any as Result<Array<UserVO>>
}

export function findDepartmentAll(): Result<DepartmentVO> {
    return request({
        url: '/department/all',
        method: 'get',
    }) as any as Result<DepartmentVO>
}

export function findPositionAll(): Result<Array<PositionVO>> {
    return request({
        url: '/position/all',
        method: 'get',
    }) as any as Result<Array<PositionVO>>
}

export function tableDetailed(data: { tablePid: string }): Result<TableDetailedVO> {
    return request({
        url: '/table/tableDetailed',
        method: 'get',
        params: data
    }) as any as Result<TableDetailedVO>
}

export function changeClassify(data: { tableClassifyPid: string, pid: string }): Result<any> {
    return request({
        url: '/table/changeClassify',
        method: 'post',
        params: data
    }) as any as Result<any>
}

export function createTable(data: any): Result<any> {
    return request({
        url: '/table/createTable',
        method: 'post',
        data: data
    }) as any as Result<any>
}

export function saveTablePermission(data: any): Result<any> {
    return request({
        url: '/table/saveTablePermission',
        method: 'post',
        data: data
    }) as any as Result<any>
}

export function updateTable(data: any): Result<any> {
    return request({
        url: '/table/updateTable',
        method: 'post',
        data: data
    }) as any as Result<any>
}

export function dataImport(data: DataImportBO): Result<any> {
    return request({
        url: '/table/dataImport',
        method: 'post',
        data: data
    }) as any as Result<any>
}

export function getImportProgress(data: { importPid: string }): Result<ImportResultVO> {
    return request({
        url: '/table/getImportProgress',
        method: 'get',
        params: data
    }) as any as Result<ImportResultVO>
}

export function download(data: { s3Key: string }): any {
    return request({
        url: '/upload/download',
        method: 'get',
        params: data,
        responseType: 'blob'
    })
}

export function batchDeleteData(data: { importPid: string }): Result<any> {
    return request({
        url: '/table/batchDeleteData',
        method: 'delete',
        params: data
    }) as any as Result<any>
}

export function recordPage(data: any): Result<Array<ImportPageVO>> {
    return request({
        url: '/import/recordPage',
        method: 'post',
        data: data
    }) as any as Result<Array<ImportPageVO>>
}

export function getTableField(data: { tablePid: string }): Result<Array<TableFieldVO>> {
    return request({
        url: '/table/getTableField',
        method: 'get',
        params: data
    }) as any as Result<Array<TableFieldVO>>
}

export function getCommonSearch(data: { tablePid: string }): Result<Array<CommonSearchVO>> {
    return request({
        url: '/table/getCommonSearch',
        method: 'get',
        params: data
    }) as any as Result<Array<CommonSearchVO>>
}

export function saveCommonSearch(data: any): Result<any> {
    return request({
        url: '/table/saveCommonSearch',
        method: 'post',
        data: data
    }) as any as Result<any>
}

export function dataPageList(data: any): Result<Array<any>> {
    return request({
        url: '/table/dataPageList',
        method: 'post',
        data: data
    }) as any as Result<Array<any>>
}

export function batchDeleteById(data: { ids: number[], tablePid: string }): Result<any> {
    return request({
        url: `/table/batchDeleteById/${data.tablePid}`,
        method: 'post',
        data: data.ids
    }) as any as Result<any>
}

export function getIdentityByTable(data: { tablePid: string }): Result<number> {
    return request({
        url: '/table/getIdentityByTable',
        method: 'get',
        params: data
    }) as any as Result<number>
}

export function findUserAllByUserPid(data: Array<string>): Result<UserVO[]> {
    return request({
        url: '/user/findUserAllByUserPid',
        method: 'post',
        data: data
    }) as any as Result<UserVO[]>
}

export function getTablePermission(data: { tablePid: string }): Result<Permission> {
    return request({
        url: '/table/getTablePermission',
        method: 'get',
        params: data
    }) as any as Result<Permission>
}

export function saveClassify(data: { classifyName: string }): Result<any> {
    return request({
        url: '/classify/saveClassify',
        method: 'post',
        params: data
    }) as any as Result<any>
}

export function deleteCommonSearchByPid(data: { pid: string }): Result<any> {
    return request({
        url: '/table/deleteCommonSearchByPid',
        method: 'delete',
        params: data
    }) as any as Result<any>
}

export function deleteAllByCriteriaRequest(data: any): Result<number> {
    return request({
        url: '/table/deleteAllByCriteria',
        method: 'delete',
        data: data
    }) as any as Result<any>
}

export function getSheetContent(data: { importPid: string, sheetName: string }): Result<ExcelDomain> {
    return request({
        url: '/upload/getSheetContent',
        method: 'get',
        params: data
    }) as any as Result<ExcelDomain>
}

export function classifyListTree(): Result<Array<DepartmentClassifyVO>> {
    return request({
        url: '/classify/classifyListTree',
        method: 'get'
    }) as any as Result<Array<DepartmentClassifyVO>>
}

export function classifyListByClassify(data: { tableClassifyPid: string }): Result<Array<Classify>> {
    return request({
        url: '/classify/classifyListByClassify',
        method: 'get',
        params: data
    }) as any as Result<Array<Classify>>

}
